package cn.zt.ztzx.config;

import cn.zt.ztzx.handler.MyHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: 天山一剑卓不凡
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    //设置跨域
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("*")
                .allowedOriginPatterns("*")
                .allowedHeaders("*")
                .allowCredentials(true);
    }

    @Autowired
    private MyHandler myHandler;
    //添加拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截所有的请求
        registry.addInterceptor(myHandler).addPathPatterns("/**")
                //放行指定的路径 请求
                .excludePathPatterns("/admin/login","/doc.html","/webjars/**","/v3/**");
    }
}
